package com.ygqh.baby.model;

import java.util.*;

/**
 * @Author: sunshuo
 * @Date: 2019/9/18/018 11:15
 * @Version: 1.0
 */
public class ProcessUserReportWrapper {

    private Date startDate;

    private Date endDate;

    private Set<Long> userIdList;

    private Map<String, ProcessUserReportDetailWrapper> detailMap;

    public ProcessUserReportWrapper(Date startDate, Date endDate) {
        this.startDate = startDate;
        this.endDate = endDate;
        this.userIdList = new HashSet<>();
        this.detailMap = new HashMap<>();
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Set<Long> getUserIdList() {
        return userIdList;
    }

    public void setUserIdList(Set<Long> userIdList) {
        this.userIdList = userIdList;
    }

    public Map<String, ProcessUserReportDetailWrapper> getDetailMap() {
        return detailMap;
    }

    public void setDetailMap(Map<String, ProcessUserReportDetailWrapper> detailMap) {
        this.detailMap = detailMap;
    }

    public void addUserId(Long userId) {
        this.userIdList.add(userId);
    }

    public ProcessUserReportDetailWrapper addDetailWrapper(String customerId, String customerName) {
        ProcessUserReportDetailWrapper detailWrapper = new ProcessUserReportDetailWrapper(customerName);
        this.detailMap.put(customerId, detailWrapper);
        return detailWrapper;
    }

    public ProcessUserReport build(Date reportDate) {
        ProcessUserReport report = new ProcessUserReport();
        report.setReportDate(reportDate);
        report.setUserCount((long) this.userIdList.size());
        List<ProcessUserReport.ProcessUserReportDetail> detailList = new ArrayList<>(this.detailMap.size());
        this.detailMap.forEach((customerId, detailWrapper) -> {
            ProcessUserReport.ProcessUserReportDetail detail = new ProcessUserReport.ProcessUserReportDetail();
            detail.setCustomerId(customerId);
            detail.setCustomerName(detailWrapper.getCustomerName());
            detail.setUserCount((long) detailWrapper.getUserIdList().size());
            detailList.add(detail);
        });
        report.setDetailList(detailList);
        return report;
    }

    public class ProcessUserReportDetailWrapper {

        /**
         * 客服名称
         */
        private String customerName;

        private Set<Long> userIdList;

        public ProcessUserReportDetailWrapper(String customerName) {
            this.customerName = customerName;
            this.userIdList = new HashSet<>();
        }

        public String getCustomerName() {
            return customerName;
        }

        public void setCustomerName(String customerName) {
            this.customerName = customerName;
        }

        public Set<Long> getUserIdList() {
            return userIdList;
        }

        public void setUserIdList(Set<Long> userIdList) {
            this.userIdList = userIdList;
        }

        public void addUserId(Long userId) {
            this.userIdList.add(userId);
        }
    }
}
